﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;
using Asd.MP.AppService.Services;

namespace Asd.MP.AppService
{
    [ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class PlatformWork
    {

        [OperationContract]
        [WebGet]
        public string DoWork(string endpoint, string method, string args)
        {
            string result = string.Empty;
            object[] parameters = string.IsNullOrEmpty(args) ? null : args.Split(',');
            EndpointAddress address = new EndpointAddress(endpoint);
            BasicHttpBinding bind = new BasicHttpBinding();
            ChannelFactory<ICoreServer> factory = new ChannelFactory<ICoreServer>(bind, address);
            factory.Open();
            ICoreServer server = factory.CreateChannel();
            result = server.DoWork(method, parameters);
            factory.Close();
            return result;
        }
    }
}
